﻿<html DIR="LTR" xmlns:tool="http://www.microsoft.com/tooltip" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ddue="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
  <head>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=utf-8" />
    <META NAME="save" CONTENT="history" />
    <title>getColumns Method (SQLServerDatabaseMetaData)</title>
    
    <link rel="stylesheet" type="text/css" href="../local/Classic.css">
      
    </link>
    
    <script src="../local/script.js">
      
    </script><script src="../local/script_main.js">&amp;nbsp;</script>
  </head>
  <body>
    <!--Topic built:03/26/2010 02:49:39-->

    
    
    
    
    
    
    
    
    
    <div id="header">
      <table width="100%" id="topTable"><tr>
          <td align="left">
            <span id="headerBold">getColumns Method (SQLServerDatabaseMetaData)</span>
          </td>
          <td align="right">
            
          </td>
        </tr></table>
      
      
      
    </div>
    <div id="mainSection">
      
        
        
    <font color="DarkGray">
      
    </font>
    <p />
    
    <p />
  
        <div id="introductionSection" class="section">
    <p>Retrieves a description of the table columns that are available in the specified catalog.</p>
  </div><h1 class="heading">Syntax</h1><div id="syntaxSection" class="section"><div class="sampleCode"><span codeLanguage="other"><pre>
public java.sql.ResultSet <b>getColumns</b>(java.lang.String <i>catalog</i>,
                                     java.lang.String <i>schema</i>,
                                     java.lang.String <i>table</i>,
                                     java.lang.String <i>col</i>)</pre></span></div><h1 class="heading">Parameters</h1><div id="parametersSection" class="section" name="collapseableSection">
    <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
      <p xmlns="">
        <i>catalog</i>
      </p>
      <p xmlns="">A<b> String </b>that contains the catalog name.</p>
      <p xmlns="">
        <i>schema</i>
      </p>
      <p xmlns="">A<b> String </b>that contains the schema name pattern.</p>
      <p xmlns="">
        <i>table</i>
      </p>
      <p xmlns="">A<b> String </b>that contains the table name pattern.</p>
      <p xmlns="">
        <i>col</i>
      </p>
      <p xmlns="">A<b> String </b>that contains the column name pattern.</p>
    </content>
  </div></div><h1 class="heading">Return Value</h1><div id="returnValueSection" class="section" name="collapseableSection">
    <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
      <p xmlns="">A <a href="eaffcff1-286c-459f-83da-3150778480c9.htm">SQLServerResultSet</a> object.</p>
    </content>
  </div><h1 class="heading">Exceptions</h1><div id="exceptionsSection" class="section" name="collapseableSection">
    <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
      <p xmlns="">
        <a href="af5ef257-7cf6-4db3-b1ee-07d22d82bef1.htm">SQLServerException</a>
      </p>
    </content>
  </div><h1 class="heading">Remarks</h1><div id="remarksSection" class="section" name="collapseableSection">
    <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
      <p xmlns="">This <b>getColumns</b> method is specified by the <b>getColumns</b> method in the java.sql.DatabaseMetaData interface.</p>
      <p xmlns="">The result set returned by the <b>getColumns</b> method will contain the following information:</p>
      <table width="100%" cellspacing="0" cellpadding="0" border="1" style="background-color: #CCCCCC;" xmlns=""><tr>
            <th>
              Name
            </th>
            <th>
              Type
            </th>
            <th>
              Description
            </th>
          </tr><tr>
          <td>
            <p>TABLE_CAT</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The catalog name.</p>
          </td>
        </tr><tr>
          <td>
            <p>TABLE_SCHEM</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The table schema name.</p>
          </td>
        </tr><tr>
          <td>
            <p>TABLE_NAME</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The table name.</p>
          </td>
        </tr><tr>
          <td>
            <p>COLUMN_NAME</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The column name.</p>
          </td>
        </tr><tr>
          <td>
            <p>DATA_TYPE</p>
          </td>
          <td>
            <p>
              <b>smallint</b>
            </p>
          </td>
          <td>
            <p>The SQL data type from java.sql.Types.</p>
          </td>
        </tr><tr>
          <td>
            <p>TYPE_NAME</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The name of the data type.</p>
          </td>
        </tr><tr>
          <td>
            <p>COLUMN_SIZE</p>
          </td>
          <td>
            <p>
              <b>int</b>
            </p>
          </td>
          <td>
            <p>The precision of the column.</p>
          </td>
        </tr><tr>
          <td>
            <p>BUFFER_LENGTH</p>
          </td>
          <td>
            <p>
              <b>smallint</b>
            </p>
          </td>
          <td>
            <p>Transfer size of the data.</p>
          </td>
        </tr><tr>
          <td>
            <p>DECIMAL_DIGITS</p>
          </td>
          <td>
            <p>
              <b>smallint</b>
            </p>
          </td>
          <td>
            <p>The scale of the column.</p>
          </td>
        </tr><tr>
          <td>
            <p>NUM_PREC_RADIX</p>
          </td>
          <td>
            <p>
              <b>smallint</b>
            </p>
          </td>
          <td>
            <p>The radix of the column.</p>
          </td>
        </tr><tr>
          <td>
            <p>NULLABLE</p>
          </td>
          <td>
            <p>
              <b>smallint</b>
            </p>
          </td>
          <td>
            <p>Indicates if the column is nullable. It can be one of the following values:</p>
            <p>columnNoNulls (0)</p>
            <p>columnNullable (1)</p>
          </td>
        </tr><tr>
          <td>
            <p>REMARKS</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The comments associated with the column.</p>
            <div style="margin: .5em 1.5em .5em 1.5em"><b>Note: </b>
              SQL Server always returns null for this column.<p />
            </div>
          </td>
        </tr><tr>
          <td>
            <p>COLUMN_DEF</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The default value of the column.</p>
          </td>
        </tr><tr>
          <td>
            <p>SQL_DATA_TYPE</p>
          </td>
          <td>
            <p>
              <b>smallint</b>
            </p>
          </td>
          <td>
            <p>Value of the SQL data type as it appears in the TYPE field of the descriptor. This column is the same as the DATA_TYPE column, except for the datetime and SQL-92 interval data types. This column always returns a value.</p>
          </td>
        </tr><tr>
          <td>
            <p>SQL_DATETIME_SUB</p>
          </td>
          <td>
            <p>
              <b>smallint</b>
            </p>
          </td>
          <td>
            <p>Subtype code for datetime and SQL-92 interval data types. For other data types, this column returns NULL.</p>
          </td>
        </tr><tr>
          <td>
            <p>CHAR_OCTET_LENGTH</p>
          </td>
          <td>
            <p>
              <b>int</b>
            </p>
          </td>
          <td>
            <p>The maximum number of bytes in the column.</p>
          </td>
        </tr><tr>
          <td>
            <p>ORDINAL_POSITION</p>
          </td>
          <td>
            <p>
              <b>int</b>
            </p>
          </td>
          <td>
            <p>The index of the column within the table.</p>
          </td>
        </tr><tr>
          <td>
            <p>IS_NULLABLE</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>Indicates if the column allows null values.</p>
          </td>
        </tr><tr>
          <td>
            <p>SS_IS_SPARSE</p>
          </td>
          <td>
            <p>
              <b>smallint</b>
            </p>
          </td>
          <td>
            <p>If the column is a sparse column, this has the value VARIANT_TRUE; otherwise, VARIANT_FALSE.</p>
          </td>
        </tr><tr>
          <td>
            <p>SS_IS_COLUMN_SET</p>
          </td>
          <td>
            <p>
              <b>smallint</b>
            </p>
          </td>
          <td>
            <p>If the column is the sparse column_set column, this has the value VARIANT_TRUE; otherwise, VARIANT_FALSE.</p>
          </td>
        </tr><tr>
          <td>
            <p>SS_IS_COMPUTED</p>
          </td>
          <td>
            <p>
              <b>smallint</b>
            </p>
          </td>
          <td>
            <p>Indicates if a column in a TABLE_TYPE is a computed column.</p>
          </td>
        </tr><tr>
          <td>
            <p>IS_AUTOINCREMENT</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>"YES" if the column is auto incremented. "NO" if the column is not auto incremented. "" (empty string) if the driver cannot determine if the column is auto incremented.</p>
          </td>
        </tr><tr>
          <td>
            <p>SS_UDT_CATALOG_NAME</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The name of the catalog that contains the user-defined type (UDT).</p>
          </td>
        </tr><tr>
          <td>
            <p>SS_UDT_SCHEMA_NAME</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The name of the schema that contains the user-defined type (UDT).</p>
          </td>
        </tr><tr>
          <td>
            <p>SS_UDT_ASSEMBLY_TYPE_NAME</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The fully-qualified name user-defined type (UDT).</p>
          </td>
        </tr><tr>
          <td>
            <p>SS_XML_SCHEMACOLLECTION_CATALOG_NAME</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The name of the catalog where an XML schema collection name is defined. If the catalog name cannot be found, this variable contains an empty string.</p>
          </td>
        </tr><tr>
          <td>
            <p>SS_XML_SCHEMACOLLECTION_SCHEMA_NAME</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The name of the schema where an XML schema collection name is defined. If the schema name cannot be found, this is an empty string.</p>
          </td>
        </tr><tr>
          <td>
            <p>SS_XML_SCHEMACOLLECTION_NAME</p>
          </td>
          <td>
            <p>
              <b>String</b>
            </p>
          </td>
          <td>
            <p>The name of an XML schema collection. If the name cannot be found, this is an empty string.</p>
          </td>
        </tr><tr>
          <td>
            <p>SS_DATA_TYPE</p>
          </td>
          <td>
            <p>
              <b>tinyint</b>
            </p>
          </td>
          <td>
            <p>The SQL Server data type that is used by extended stored procedures.</p>
            <p>
              <b>Note</b>   For more information about the data types returned by SQL Server, see "Data Types (Transact-SQL)" in SQL Server Books Online. </p>
          </td>
        </tr></table>
      <div style="margin: .5em 1.5em .5em 1.5em" xmlns=""><b>Note: </b>
        For more information about the data returned by the <b>getColumns</b> method, see "sp_columns (Transact-SQL)" in SQL Server Books Online.<p />
      </div>
      <p xmlns="">In the Microsoft SQL Server JDBC Driver 3.0, you will see the following behavior changes from earlier versions of the JDBC Driver:</p>
      <p xmlns="">The DATA_TYPE column has the following changes:</p>
      <table width="100%" cellspacing="0" cellpadding="0" border="1" style="background-color: #CCCCCC;" xmlns=""><tr>
            <th>
              
                SQL Server Data Type
            </th>
            <th>
              Return Type in JDBC Driver 2.0 and Associated Numeric Constant
            </th>
            <th>
              Return Type in JDBC Driver 3.0
            </th>
          </tr><tr>
          <td>
            <p>user-defined type larger than 8 kB</p>
          </td>
          <td>
            <p>LONGVARBINARY (-4)</p>
          </td>
          <td>
            <p>VARBINARY (-3)</p>
          </td>
        </tr><tr>
          <td>
            <p>geography</p>
          </td>
          <td>
            <p>LONGVARBINARY (-4)</p>
          </td>
          <td>
            <p>VARBINARY (-3)</p>
          </td>
        </tr><tr>
          <td>
            <p>geometry</p>
          </td>
          <td>
            <p>LONGVARBINARY (-4)</p>
          </td>
          <td>
            <p>VARBINARY (-3)</p>
          </td>
        </tr><tr>
          <td>
            <p>varbinary(max)</p>
          </td>
          <td>
            <p>LONGVARBINARY (-4)</p>
          </td>
          <td>
            <p>VARBINARY (-3)</p>
          </td>
        </tr><tr>
          <td>
            <p>nvarchar(max)</p>
          </td>
          <td>
            <p>LONGVARCHAR (-1) or LONGNVARCHAR (JDBC 4) (-16)</p>
          </td>
          <td>
            <p>VARCHAR (12) or NVARCHAR (JDBC 4) (-9)</p>
          </td>
        </tr><tr>
          <td>
            <p>varchar(max)</p>
          </td>
          <td>
            <p>LONGVARCHAR (-1)</p>
          </td>
          <td>
            <p>VARCHAR (12)</p>
          </td>
        </tr><tr>
          <td>
            <p>time</p>
          </td>
          <td>
            <p>VARCHAR (12) or NVARCHAR (JDBC 4) (-9)</p>
          </td>
          <td>
            <p>TIME (-154)</p>
          </td>
        </tr><tr>
          <td>
            <p>date</p>
          </td>
          <td>
            <p>VARCHAR (12) or NVARCHAR (JDBC 4) (-9)</p>
          </td>
          <td>
            <p>DATE (91)</p>
          </td>
        </tr><tr>
          <td>
            <p>datetime2</p>
          </td>
          <td>
            <p>VARCHAR (12) or NVARCHAR (JDBC 4) (-9)</p>
          </td>
          <td>
            <p>TIMESTAMP (93)</p>
          </td>
        </tr><tr>
          <td>
            <p>datetimeoffset</p>
          </td>
          <td>
            <p>VARCHAR (12) or NVARCHAR (JDBC 4) (-9)</p>
          </td>
          <td>
            <p>microsoft.sql.Types.DATETIMEOFFSET  (-155)</p>
          </td>
        </tr></table>
      <p xmlns="">The COLUMN_SIZE column has the following changes:</p>
      <table width="100%" cellspacing="0" cellpadding="0" border="1" style="background-color: #CCCCCC;" xmlns=""><tr>
            <th>
              
                SQL Server Data Type
            </th>
            <th>
              Return Type in JDBC Driver 2.0
            </th>
            <th>
              Return Type in JDBC Driver 3.0
            </th>
          </tr><tr>
          <td>
            <p>nvarchar(max)</p>
          </td>
          <td>
            <p>1073741823</p>
          </td>
          <td>
            <p>2147483647 (database metadata)</p>
          </td>
        </tr><tr>
          <td>
            <p>xml</p>
          </td>
          <td>
            <p>1073741823</p>
          </td>
          <td>
            <p>2147483647 (database metadata)</p>
          </td>
        </tr><tr>
          <td>
            <p>user-defined type less than or equal to 8 kB</p>
          </td>
          <td>
            <p>8 kB (result set and parameter metadata)</p>
          </td>
          <td>
            <p>Actual size returned by the stored procedure.</p>
          </td>
        </tr><tr>
          <td>
            <p>time</p>
          </td>
          <td>
            <p> </p>
          </td>
          <td>
            <p>The length in characters of the string representation of the type, assuming the maximum allowed precision of the fractional seconds' component.</p>
          </td>
        </tr><tr>
          <td>
            <p>date</p>
          </td>
          <td>
            <p> </p>
          </td>
          <td>
            <p>same as time</p>
          </td>
        </tr><tr>
          <td>
            <p>datetime2</p>
          </td>
          <td>
            <p> </p>
          </td>
          <td>
            <p>same as time</p>
          </td>
        </tr><tr>
          <td>
            <p>datetimeoffset</p>
          </td>
          <td>
            <p> </p>
          </td>
          <td>
            <p>same as time</p>
          </td>
        </tr></table>
      <p xmlns="">The BUFFER_LENGTH column has the following change:</p>
      <table width="100%" cellspacing="0" cellpadding="0" border="1" style="background-color: #CCCCCC;" xmlns=""><tr>
            <th>
              
                SQL Server Data Type
            </th>
            <th>
              Return Type in JDBC Driver 2.0
            </th>
            <th>
              Return Type in JDBC Driver 3.0
            </th>
          </tr><tr>
          <td>
            <p>user-defined type larger than 8 kB</p>
          </td>
          <td>
          </td>
          <td>
            <p>2147483647</p>
          </td>
        </tr></table>
      <p xmlns="">The TYPE_NAME column has the following changes:</p>
      <table width="100%" cellspacing="0" cellpadding="0" border="1" style="background-color: #CCCCCC;" xmlns=""><tr>
            <th>
              
                SQL Server Data Type
            </th>
            <th>
              Return Type in JDBC Driver 2.0
            </th>
            <th>
              Return Type in JDBC Driver 3.0
            </th>
          </tr><tr>
          <td>
            <p>varchar(max)</p>
          </td>
          <td>
            <p>text</p>
          </td>
          <td>
            <p>varchar</p>
          </td>
        </tr><tr>
          <td>
            <p>varbinary(max)</p>
          </td>
          <td>
            <p>image</p>
          </td>
          <td>
            <p>varbinary</p>
          </td>
        </tr></table>
      <p xmlns="">The DECIMAL_DIGITS column has the following changes:</p>
      <table width="100%" cellspacing="0" cellpadding="0" border="1" style="background-color: #CCCCCC;" xmlns=""><tr>
            <th>
              
                SQL Server Type
            </th>
            <th>
              JDBC Driver 2.0
            </th>
            <th>
              JDBC Driver 3.0
            </th>
          </tr><tr>
          <td>
            <p>time</p>
          </td>
          <td>
            <p>null</p>
          </td>
          <td>
            <p>7 (or smaller if specified)</p>
          </td>
        </tr><tr>
          <td>
            <p>date</p>
          </td>
          <td>
            <p>null</p>
          </td>
          <td>
            <p>null</p>
          </td>
        </tr><tr>
          <td>
            <p>datetime2</p>
          </td>
          <td>
            <p>null</p>
          </td>
          <td>
            <p>7 (or smaller if specified)</p>
          </td>
        </tr><tr>
          <td>
            <p>datetimeoffset</p>
          </td>
          <td>
            <p>null</p>
          </td>
          <td>
            <p>7 (or smaller if specified)</p>
          </td>
        </tr></table>
      <p xmlns="">The SQL_DATA_TYPE column has the following changes:</p>
      <table width="100%" cellspacing="0" cellpadding="0" border="1" style="background-color: #CCCCCC;" xmlns=""><tr>
            <th>
              
                SQL Server Data Type
            </th>
            <th>
              
                SQL Server 2008 Data Value in JDBC Driver 2.0
            </th>
            <th>
              
                SQL Server 2008 Data Value in JDBC Driver 3.0
            </th>
          </tr><tr>
          <td>
            <p>varchar(max)</p>
          </td>
          <td>
            <p>-10</p>
          </td>
          <td>
            <p>-9</p>
          </td>
        </tr><tr>
          <td>
            <p>nvarchar(max)</p>
          </td>
          <td>
            <p>-1</p>
          </td>
          <td>
            <p>-9</p>
          </td>
        </tr><tr>
          <td>
            <p>xml</p>
          </td>
          <td>
            <p>-10</p>
          </td>
          <td>
            <p>-152</p>
          </td>
        </tr><tr>
          <td>
            <p>user-defined type less than or equal to 8 kB</p>
          </td>
          <td>
            <p>-3</p>
          </td>
          <td>
            <p>-151</p>
          </td>
        </tr><tr>
          <td>
            <p>user-defined type larger than 8 kB</p>
          </td>
          <td>
            <p>Not available in JDBC Driver 2.0</p>
          </td>
          <td>
            <p>-151</p>
          </td>
        </tr><tr>
          <td>
            <p>geography</p>
          </td>
          <td>
            <p>-4</p>
          </td>
          <td>
            <p>-151</p>
          </td>
        </tr><tr>
          <td>
            <p>geometry</p>
          </td>
          <td>
            <p>-4</p>
          </td>
          <td>
            <p>-151</p>
          </td>
        </tr><tr>
          <td>
            <p>hierarchyid</p>
          </td>
          <td>
            <p>-4</p>
          </td>
          <td>
            <p>-151</p>
          </td>
        </tr><tr>
          <td>
            <p>time</p>
          </td>
          <td>
            <p>-9</p>
          </td>
          <td>
            <p>92</p>
          </td>
        </tr><tr>
          <td>
            <p>date</p>
          </td>
          <td>
            <p>-9</p>
          </td>
          <td>
            <p>91</p>
          </td>
        </tr><tr>
          <td>
            <p>datetime2</p>
          </td>
          <td>
            <p>-9</p>
          </td>
          <td>
            <p>93</p>
          </td>
        </tr><tr>
          <td>
            <p>datetimeoffset</p>
          </td>
          <td>
            <p>-9</p>
          </td>
          <td>
            <p>-155</p>
          </td>
        </tr></table>
    </content>
  </div><h1 class="heading">Example</h1><div id="codeExampleSection" class="section" name="collapseableSection">
    <description xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
      <content>
        <p xmlns="">The following example demonstrates how to use the <b>getColumns</b> method to return information for the FirstName column in the Person.Contact table in the SQL Server 2005 AdventureWorks sample database.</p>
      </content>
    </description>
    <div class="sampleCode"><span codeLanguage="other"><pre>public static void executeGetColumns(Connection con) {
   try {
      DatabaseMetaData dbmd = con.getMetaData();
      ResultSet rs = dbmd.getColumns("AdventureWorks", "Person", "Contact", "FirstName");
      ResultSetMetaData rsmd = rs.getMetaData();

      // Display the result set data.
      int cols = rsmd.getColumnCount();
      while(rs.next()) {
         for (int i = 1; i &lt;= cols; i++) {
            System.out.println(rs.getString(i));
         }
      }
      rs.close();
   } 

   catch (Exception e) {
      e.printStackTrace();
   }
}</pre></span></div>
  </div><span id="seeAlsoSpan"><h1 class="heading">See Also</h1></span><div id="seeAlsoSection" class="section" name="collapseableSection"><a href="8b8049d0-8c6d-4476-866b-098709f37eec.htm">SQLServerDatabaseMetaData Class</a><br /><a href="772de447-c922-4b85-8e10-5f0d9277966c.htm">SQLServerDatabaseMetaData Methods</a><br /><a href="327ba0bc-438a-494c-b119-1cd4a096bb58.htm">SQLServerDatabaseMetaData Members</a><br /><br /></div><!--[if gte IE 5]>
			<tool:tip element="seeAlsoToolTip" avoidmouse="false"/><tool:tip element="languageFilterToolTip" avoidmouse="false"/><tool:tip element="roleInfoSpan" avoidmouse="false"/>
		<![endif]-->
      <div id="footer" class="section">
        
		<hr />
		
		<span id="fb" class="feedbackcss">
			
			
		</span>
		
		<a href="9bad553b-9e70-4696-8499-2e35f772a1e0.htm">
			
			© 2010 Microsoft Corporation. All rights reserved.
		</a>
 	
	
      </div>
    </div>
  </body>
</html>